import request from "@/axios"

export default ({
  namespaced:true,
  state: {
      // 举报组件信息
      ReportInfo:{state:false,title:'未定义',report:{}},
      //申述组件信息
      AppealInfo:{state:false,title:'未定义',appeal:{}},

      //系统消息
      SystemInfoState:false,
  },
  getters: {},
  mutations: {
    //设置举报组件信息
    SETREPORT:(state,info) =>{
      if(!info)  state.ReportInfo ={state:false,title:'未定义',report:{}}
        state.ReportInfo = {...state.ReportInfo,...info}
     },

     //设置申诉组件信息
    SETAPPEAL:(state,info) =>{
      if(!info)  state.AppealInfo ={state:false,title:'未定义',appeal:{}}
        state.AppealInfo = {...state.AppealInfo,...info}
     },

     //设置系统消息
     SETSYSTEMINFO:(state,SystemInfoState) =>{
        if(SystemInfoState) state.SystemInfoState = true
        else state.SystemInfoState = false
     }


  },
  actions:{
    async addReport({dispatch,commit},report){
       try{
          let res = await request.post('/api/report/add',report)
          return res.data
       }catch (error) {return{code:400,message:error}}
    },
    async addAppeal({dispatch,commit},appeal){
      try{
         let res = await request.post('/api/appeal/add',appeal)
         return res.data
      }catch (error) {return{code:400,message:error}}
   },
  },
})